#include <iostream>
#include <string>
#include <vector>
using namespace std;

// class Solution {
// public:
//     int hIndex(vector<int>& citations) {
//         int n = citations.size();
//         vector<int> papers(n + 1, 0);
//         for (int c : citations) {
//             papers[min(c, n)]++;
//         }
//         int k = n;
//         for (int s = papers[n]; k > s; s += papers[k]) {
//             k--;
//         }
//         return k;      
//     }
// };

class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        int citations_sum = 0;
        vector<int> tmep_vector(n, 0);
        for (size_t i = n; i > 0; i--) {
            for (size_t j = 0; j < n; j++) {
                if (citations[j] >= i) {
                    tmep_vector[j] = 1;
                }
            }
            for (size_t k = 0; k < n; k++) {
                citations_sum += tmep_vector[k];
            }
            if (citations_sum >= i) {
                return i;
            }
            citations_sum = 0;
        }
        return 0;
    }
};

int main(int argc, char *argv[]) {
    Solution solution;
    vector<int> citations = {3, 0, 6, 1, 5};
    int result = solution.hIndex(citations);
    cout << "Result: " << result << endl;
    return 0;
}